<?php

use yii\db\Migration;

class m240417_014729_diandi_hotel_member_coupon extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%diandi_hotel_member_coupon}}', [
            'id' => "int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '会员卡券id'",
            'bloc_id' => "int(11) NULL COMMENT '人脸库组id'",
            'store_id' => "int(11) NULL",
            'create_time' => "datetime NULL",
            'update_time' => "datetime NULL",
            'member_id' => "int(11) NULL COMMENT '会员id'",
            'coupon_name' => "varchar(100) NOT NULL COMMENT '卡券名称'",
            'status' => "int(11) NULL COMMENT '卡券状态'",
            'coupon_type' => "smallint(6) NULL COMMENT '卡券类型  1：代金券 2：时常卡  3：次卡 4：折扣券 5：体验券'",
            'coupon_id' => "int(11) NULL COMMENT '卡券id'",
            'buy_time' => "datetime NULL COMMENT '购买时间'",
            'end_time' => "datetime NULL COMMENT '到期时间'",
            'use_time' => "datetime NULL COMMENT '使用时间'",
            'use_num' => "smallint(6) NULL DEFAULT '0' COMMENT '使用次数'",
            'surplus_num' => "smallint(6) NULL DEFAULT '0' COMMENT '剩余次数'",
            'receive_type' => "smallint(6) NULL COMMENT '领取方式：1.领取 2.购买 3.充值赠送'",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='用户卡券表'");
        
        /* 索引设置 */
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%diandi_hotel_member_coupon}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

